from tkinter import *
import image
import network


OPT_ACTIVE = True       # 窗口的操作是否有效。有需要的函数都应该需要验证


class Canvas(Canvas):
    def __init__(self, master, **kwargs):
        super().__init__(master, **kwargs)
        # self.event_expression = []      # 里面是事件表达式，如 ('not in', CLICK_TAG, 'search_label', func)

    def create_round_rect(self, x1, y1, x2, y2, radius, outline=None, fill=None, width=1, tag=None):
        if fill:
            self.create_arc(x1, y1, x1 + radius * 2, y1 + radius * 2, start=90, outline=outline, fill=fill, width=width, tag=tag, style=PIESLICE)

            self.create_arc(x2 - radius * 2, y1, x2, y1 + radius * 2, start=0, outline=outline, fill=fill, width=width, tag=tag, style=PIESLICE)

            self.create_arc(x1, y2 - radius * 2, x1 + radius * 2, y2, start=180, outline=outline, fill=fill, width=width, tag=tag, style=PIESLICE)

            self.create_arc(x2 - radius * 2, y2 - radius * 2, x2, y2, start=270, outline=outline, fill=fill, width=width, tag=tag, style=PIESLICE)

            self.create_rectangle(x1+radius-width/2, y1+width/2, x2-radius+width/2, y1+radius+width/2, width=0, fill=fill, tag=tag)
            self.create_rectangle(x1+width/2, y1+radius-width/2, x2-width/2, y2-radius+width/2, width=0, fill=fill, tag=tag)
            self.create_rectangle(x1+radius-width/2, y2-width/2, x2-radius+width/2, y2-radius+width/2, width=0, fill=fill, tag=tag)

        else:
            self.create_arc(x1, y1, x1 + radius * 2, y1 + radius * 2, start=90, outline=outline, width=width,
                            tag=tag, style=ARC)

            self.create_arc(x2 - radius * 2, y1, x2, y1 + radius * 2, start=0, outline=outline, width=width,
                            tag=tag, style=ARC)

            self.create_arc(x1, y2 - radius * 2, x1 + radius * 2, y2, start=180, outline=outline,
                            width=width, tag=tag, style=ARC)

            self.create_arc(x2 - radius * 2, y2 - radius * 2, x2, y2, start=270, outline=outline,
                            width=width, tag=tag, style=ARC)

        self.create_line(x1, y1 + radius, x1, y2 - radius, fill=outline, width=width, tag=tag)
        self.create_line(x1 + radius, y1, x2 - radius, y1, fill=outline, width=width, tag=tag)
        self.create_line(x1 + radius, y2, x2 - radius, y2, fill=outline, width=width, tag=tag)
        self.create_line(x2, y1 + radius, x2, y2 - radius, fill=outline, width=width, tag=tag)


class HomePage(Canvas):
    def __init__(self, master, **kwargs):
        super().__init__(master, **kwargs)
        #self.network = network.HomePage()
        #self.latest_updates_info = self.network.get_latest_updates()
        # [{
        #                 'series_name': series_name_list[index].text,
        #                 'image': image_list[index].attrib['src'],
        #                 'episode_name': episode_name_list[index].text,
        #                 'update_time': update_time_list[index].text
        #             }, ...]

        #self.new_anime = self.network.get_new_anime()

        #self.random_anime_info = self.network.get_random_anime()
        # {
        #             'name': name,
        #             'description': describe,
        #             'genres': genres,
        #             'rating': rating,
        #             'status': status,
        #             'type': type,
        #             'first_aired': first_aired,
        #             'episode_info': list(zip(episode_name, episode_release_time)),       # 顺序从集数大到小
        #             'cover': cover
        #         }

    def start(self):
        self.create_image(0, 0, image=image.images['main background'], anchor='nw')

class Application:
    def __init__(self):
        self.window = Tk(screenName='IedAnime', baseName='IedAnime', className='IedAnime')
        self.window.title('IedAnime')
        self.window.geometry('1000x780')

        self.window['bg'] = 'white'

        image.load_local_pic('bin\\main-bg.jpg', tag='main background')
        image.load_local_pic('bin\\topimage.png', tag='top image')

        home_page = HomePage(self.window, width=1000, height=780, highlightthickness=0)
        home_page.start()
        home_page.place(x=0, y=0)


app = Application()
app.window.mainloop()

# root = Tk()
# cv = Canvas(root, width=800, height=800)
# cv.pack()
# cv.create_round_rect(200, 200, 500, 500, 10, fill='white', outline='#000000', width=3)
# root.mainloop()
